Skip to content

Fix shipping_method incorrectly sent to Amazon with imported default values (PCMT-1474)#79

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/pcmt-1474-fix-shipping-method-issues
Draft

Fix shipping_method incorrectly sent to Amazon with imported default values (PCMT-1474)#79
Copilot wants to merge 4 commits intomainfrom
copilot/pcmt-1474-fix-shipping-method-issues

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 1, 2026

  • Understand the codebase and identify files to modify
  • Fix LengowMarketplace.php: Only send shipping_method when required, or when optional and non-empty
  • Fix LengowOrderController.php: Allow saving empty value to clear shipping_method
  • Fix admin_order_side.tpl: Add empty default option, free text input, filter null values, sync JS
  • Pass lengow_locale to hookAdminOrderSide template
  • Update template to use $lengow_locale->t(...) instead of hardcoded French strings
  • Add translations to YAML source files (EN, FR, ES, IT) — the authoritative source for CSVs
  • Regenerate CSV files from YAML using tools/translate.php
Original prompt

Problem Statement

Context

Merchant reported issues with shipping_method parameter being sent incorrectly to Amazon, causing wrong shipping methods to appear on Amazon Seller Central (e.g., "Standard", "SecondDay" instead of the configured "ECONOMY").

Related Ticket: PCMT-1474
Account ID: 17025 (MAGNETRON S.A)
Marketplace: Amazon ES
Plugin Version: 3.9.4
PrestaShop Version: 1.7.8.8

Issues to Fix

1. Shipping method sent even when optional

  • Amazon API defines shipping_method as optional with accept_free_values: true
  • Current code sends default values ("Standard", "SecondDay") from the original Amazon order import
  • These values don't match merchant's Amazon Seller configuration (wants "ECONOMY")

2. No free text input field

  • Amazon accepts free text values for shipping_method
  • Plugin only shows dropdown with fixed values from API
  • Merchant cannot enter custom values like "ECONOMY" that exist in their Seller Central

3. Dropdown shows pre-selected value when nothing is saved

  • UI shows "NextDay" selected by default even when database value is NULL
  • Confusing for merchant who thinks a value is selected when it's not
  • Should show empty/blank option by default

4. "null" values appear in dropdown

  • Some shipping methods from API have lengow_code: null
  • Example: "Priority": {"label": "Priority", "lengow_code": null}
  • These "null" values pollute the dropdown list

Expected Behavior

  1. Only send shipping_method when:

    • It's a required parameter for the marketplace, OR
    • It's optional AND has a non-empty value
  2. Allow free text input:

    • Add text input field alongside dropdown
    • Merchant can type any value (e.g., "ECONOMY", "EXPRESS")
    • Text input takes priority over dropdown selection
  3. Empty by default:

    • Show "-- No shipping method selected --" option
    • Pre-select empty option when no value in database
    • No confusion about whether a value is selected
  4. Filter null values:

    • Remove shipping methods with lengow_code: null from dropdown
    • Clean display of available options

Files to Modify

Backend Changes

  1. classes/models/LengowMarketplace.php (line 507-509)
    • Modify getAllParams() method
    • Check if shipping_method is required vs optional
    • Only send if required OR (optional AND not empty)
case LengowAction::ARG_SHIPPING_METHOD:
    // Determine if shipping_method is required or optional for this marketplace
    $isRequired = isset($actions['args']) && in_array(LengowAction::ARG_SHIPPING_METHOD, $actions['args'], true);
    
    if ($isRequired) {
        // Required parameter: always send (even if empty)
        $params[$arg] = $shippingMethod ?? '';
    } else {
        // Optional parameter: only send if not empty
        // This avoids sending Amazon default values like "Standard", "SecondDay"
        if (!empty($shippingMethod)) {
            $params[$arg] = $shippingMethod;
        }
    }
    break;
  1. classes/models/LengowHook.php or controller preparing template data
    • Filter out shipping methods with null lengow_code
    • Before passing to template, filter array:
$shippingMethods = array_filter($shippingMethods, function($method) {
    return !empty($method['method_lengow_code']) 
        && $method['method_lengow_code'] !== 'null' 
        && $method['method_lengow_code'] !== 'NULL';
});
  1. classes/controllers/LengowOrderController.php (save_shipping_method action)
    • Accept free text values (not just dropdown values)
    • Allow empty/null values to be saved

Frontend Changes

  1. views/templates/hook/order/admin_order_side.tpl
    • Add "-- No shipping method selected --" as first option
    • Add free text input field below dropdown
    • Add help text explaining Amazon accepts free values
    • Sync dropdown and text field with JavaScript
    • Filter out null values in Smarty loop
    • Update save button to use text field value if filled, otherwise dropdown

Acceptance Criteria

  • When shipping_method is optional (like Amazon), it's NOT sent if empty
  • When shipping_method is required (other marketplaces), it's always sent
  • Merchant can type custom shipping method value (free text)
  • Dropdown shows "-- No shipping method selected --" when no value saved
  • No "null" values appear in dropdown list
  • Text input field takes priority over dropdown when both have values
  • Saving works correctly for both dropdown selections and custom text
  • Existing functionality for other marketplaces remains unchanged

Test Cases

  1. Test Amazon order with no shipping_method set:

    • Create/import Amazon order
    • Don't set shipping_method
    • Trigger ship action
    • Verify shipping_method parameter is NOT sent to Lengow API
  2. Test Amazon order with custom shipping_method:

    • Set custom value "ECONOMY" via text field
    • Save
    • Trigger ship ac...

This pull request was created from Copilot chat.

…ilter null values (PCMT-1474)

Agent-Logs-Url: https://github.com/lengow/plugin-prestashop/sessions/394f4513-0fb6-4d73-989d-53395654c8d8

Co-authored-by: michaelmaslengow <147600733+michaelmaslengow@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix shipping method parameter in Amazon plugin Fix shipping_method incorrectly sent to Amazon with imported default values (PCMT-1474) Apr 1, 2026
Copilot AI requested a review from michaelmaslengow April 1, 2026 08:34
@michaelmaslengow
Copy link
Copy Markdown
Contributor

@copilot

Il manque les traductions.

Agent-Logs-Url: https://github.com/lengow/plugin-prestashop/sessions/55d31c36-58eb-4b8f-adc5-25386b70d444

Co-authored-by: michaelmaslengow <147600733+michaelmaslengow@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Apr 1, 2026

@copilot

Il manque les traductions.

Added translations for all new UI strings in commit 48466f5.

Changes:

  • Added 8 new keys under admin.order.shipping_method_* to EN, FR, ES, IT CSV files
  • Updated admin_order_side.tpl to use $lengow_locale->t(...) instead of hardcoded French strings (labels, button, empty option, help text, JS feedback messages)
  • Added lengow_locale assignment in LengowHook::hookAdminOrderSide() so the translation object is available in the template

@michaelmaslengow
Copy link
Copy Markdown
Contributor

@copilot

Ca me donne : Missing Translation [admin.order.shipping_method_custom_label]

Il faut pas build autre chose en local?

Copy link
Copy Markdown
Author

Copilot AI commented Apr 1, 2026

@copilot

Ca me donne : Missing Translation [admin.order.shipping_method_custom_label]
...

The root cause was that the CSV files are generated from YAML source files by tools/translate.php (with w+ mode, which truncates on open). My previous commit added keys directly to the CSVs, but those would be wiped by any translate.php run.

Fixed in commit 1bf5055: added the 8 new admin.order.shipping_method_* keys to the authoritative YAML sources (translations/yml/en.yml, fr.yml, es.yml, it.yml), then ran tools/translate.php locally to regenerate the CSVs. No manual build step is needed on your end — the regenerated CSVs are included in the commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants